﻿using Direct.IDAL.ServiceCenterApply;
using DirectSell.Model.ServiceCenter;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DirectSell.DAL.User.ServiceCenterApply
{
    /// <summary>
    /// 服务中心数据访问层
    /// </summary>
    public class ServiceCenterRepository:AbsRepository, IServiceCenterRepository
    {
        /// <summary>
        /// 服务中心申请
        /// </summary>
        /// <param name="model">模型类</param>
        /// <returns></returns>
      public void Apply(ServiceCenter model,ref Hashtable hsTable)
      {
            var str = new StringBuilder();
            str.Append(" INSERT INTO ServiceCentre ( ");
            str.Append(" [ServiceCenterCode], ");
            str.Append(" [Name], ");
            str.Append(" [Level], ");
            str.Append(" [Address] )");
            str.Append(" VALUES ");
            str.Append(" (@ServiceCenterCode, @Name, @Level, @Address); ");
            hsTable.Add(str.ToString(), model);
        }
        /// <summary>
        /// 修改会员服务中心状态为待审核
        /// </summary>
        /// <param name="model"></param>
        /// <param name="hsTable"></param>
        public void ModifyUser(ServiceCenter model, ref Hashtable hsTable)
        {
            var str = new StringBuilder();
            str.Append(" UPDATE UserInforMations ");
            str.Append(" SET IsCenterService = 2 ");
            str.Append(" WHERE ");
            str.Append(" UserCode =@ServiceCenterCode ");
            str.Append(" AND IsCenterService = 0 ");
            hsTable.Add(str.ToString(), model);
        }
        /// <summary>
        /// 判断是否重复提交
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public  bool RepeatLock(ServiceCenter model)
        {
            StringBuilder str = new StringBuilder();
            str.Append(" SELECT count(*) FROM ServiceCentre ");
            str.AppendFormat(" WHERE  ServiceCenterCode = '{0}' ",model.ServiceCenterCode);
            var result = base.QueryFirst<long>(str.ToString());
            return result <= 0;
        }
    }
}
